package com.dalei.vdserver.shared.util;

import java.util.zip.CRC32;

public class StringChecksum {

	public static long createChecksum(final String str) {
		if (str != null) {
			CRC32 crc32 = new CRC32();
			crc32.update(str.getBytes());
			return crc32.getValue();
		} else {
			return 0xffffffff;
		}
	}

	public static boolean verifyChecksum(final String str, final long checksum) {
		if (str != null) {
			CRC32 crc32 = new CRC32();
			crc32.update(str.getBytes());
			return (crc32.getValue() == checksum);
		} else {
			return false;
		}
	}
}
